/*
  ODADialer.cpp - 
*/

#include "ODADialer.h"
#include "ODPort.h"
#include "WProgram.h"
#include "ODADebug.h"

Dialer::Dialer() {
  _off = HIGH;
  _on = LOW;
  return;
}

void Dialer::init(uint8_t callPorts[4], uint8_t smsPorts[2], uint8_t resetPort) {
  for (int i = 0; i <4; i++) {
    _callPorts[i].initOutput(callPorts[i], _off);
  }

  for (int i = 0; i <2; i++) {
    _smsPorts[i].initOutput(smsPorts[i], _off);
  }
  
  _resetPort.initOutput(resetPort, _on);
  delay(500);
  enable();
  delay(500);
  reset();
  
  _status = _off;
  _stopTime = 0;
}

void Dialer::call(uint8_t line) {
  _callPorts[line-1].setStatus(_on);
}

void Dialer::sendSms(uint8_t line) {
  _smsPorts[line-1].setStatus(_on);
}

void Dialer::disable() {
  _resetPort.setStatus(_on);
}

void Dialer::enable() {
  _resetPort.setStatus(_off);
}

void Dialer::reset() {
  for (int i = 0; i <4; i++) {
    _callPorts[i].setStatus(_off);
  }

  for (int i = 0; i <2; i++) {
    _smsPorts[i].setStatus(_off);
  }
  
  disable();
}

void Dialer::service() {
//  if (_status == _on && millis() > _stopTime)
//    stopAlarm();
}